#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   current_test.py    
@Contact :   pengwei.sun@aihuishou.com
@License :   (C)Copyright aihuishou

@Modify Time      @Author       @Version    @Desciption
------------      -----------   --------    -----------
2022-01-21 17:26   pengwei.sun      1.0         None
'''
import concurrent.futures
import time
from itertools import repeat
from concurrent.futures import ProcessPoolExecutor, wait,ThreadPoolExecutor
import threading
from multiprocessing import Pool

cpu_worker_num = 12
global count
count=0
arr=[1]*50000
# print(arr)


def fun(a):
    global count

    # time.sleep(5)
    count+=a
    print(count)
    return count
iter = 0
pool=10
t1=time.time()
resDf0=[]
count=0
# with ThreadPoolExecutor(max_workers=pool) as executor:
#     for number in executor.map(fun,arr ):
#         resDf0.append(number)
        # iter += 1
        # print('total_gp = {} ,iter={} skuid={} is prime:'.format(1000, iter, number))
t2 = time.time()
tt0=t2-t1

# print('time={}'.format(t2-t1))
resDf=[]
t1=time.time()
# with concurrent.futures.ProcessPoolExecutor(max_workers=cpu_worker_num) as executor:
#     for number in executor.map(fun,arr):
#         resDf.append(number)
        # iter += 1
        # print('total_gp = {} ,iter={} skuid={} is prime:'.format(1000, iter, number))
t2=time.time()
tt2=t2-t1


count=0
start_time = time.time()
t1=time.time()
resDf1=[]
# with Pool(cpu_worker_num) as p:
#     # outputs = p.map(fun, arr)
#     for number,gr in zip(arr,p.map(fun,arr)):
#         resDf1.append(number)
# print(f'| outputs: {resDf1}    TimeUsed: {time.time() - start_time:.1f}    \n')
t2=time.time()
tt3=t2-t1
print('time={},{},{}'.format(tt0,tt2,tt3))
# print(resDf1)
# print(resDf)

def fun(a,b):
    count=a+b
    time.sleep(10)
    print(count)
    return count

def fun1(a,b):
    count=a+b
    time.sleep(5)
    print(count)
    return count
def myfun(kws):
    a=fun(*kws)
    return a

num = [1,2,3]
# b=[3,4,5]
# # b=9
with Pool(cpu_worker_num) as p:
    # outputs = p.map(fun, arr)
    for number,gr in zip(arr,p.map(myfun,num,b)):
        resDf1.append(number)

thread_0 = threading.Thread(target=fun, args=(1,2))
thread_1 = threading.Thread(target=fun1, args=(5,7))
## now issue the two threads
thread_0.start()
thread_1.start()
thread_0.join()
thread_1.join()
print('dsds')


